package com.yang.mapper;

import com.yang.entity.Address;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressMapper {

    /**
     * 添加收货地址
     *
     * @param address 收货地址
     */
    // 默认使用收货地址
    @Insert("insert into address values" +
            "(default, #{userId}, #{addressDescription}, #{addressName}, #{addressPhone}, 1)")
    void addAddress(Address address);

    /**
     * 禁用收货地址
     *
     * @param userId    用户id
     * @param addressId 地址id
     */
    @Update("update address set status = 0 where user_id = #{userId} and address_id = #{addressId}")
    void deleteAddress(Integer userId, Integer addressId);

    /**
     * 更新收货地址
     *
     * @param address
     */
    @Update("update address set address_description = #{addressDescription}, address_name = #{addressName}, address_phone = #{addressPhone} where user_id = #{userId} and address_id = #{addressId}")
    void updateAddress(Address address);

    /**
     * 获取用户的收货地址列表
     *
     * @param userId 用户id
     * @return
     */
    @Select("SELECT * FROM address WHERE user_id = #{userId} and status = 1 order by address_id desc")
    List<Address> getAddressList(long userId);

}
